<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <style>
        .btn {
            font-size: 12px;
        }

        .lay-box {
            padding: 10px;
        }
    </style>
</head>
<body>
<title>评论任务</title>
<div class="lay-box">
    <div>
        <button type="button" class="layui-btn" id="test1">
            <i class="layui-icon">&#xe67c;</i>导入评论
        </button>
        <#--<button class="layui-btn" onclick="gradeEdit()">
            <i class="layui-icon">&#xe608;</i> 添加评论
        </button>-->
        <button class="layui-btn" onclick="search()">
            <i class="layui-icon">&#xe669;</i> 刷新
        </button>
    </div>


    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>


</body>
<style>

</style>
<script type="text/html" id="barDemo">
    <#--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="已使用|未使用" lay-filter="sexDemo" {{
           d.status== '1' ? 'checked' : '' }}>

</script>
<script type="text/javascript">
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var marketId = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "tb_task_comments_detail";

    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/sys/comments/getDetail'
            ,
            where: {
                table: table,
                commentsId: ${id},
                time: {'start': startDate, 'end': endDate},
                key: {'name': searchKey}
            }
            ,
            toolbar: true,
            method: 'POST'
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id'}
                , {
                    field: 'enable',
                    title: '状态',
                    width: 100,
                    align: 'center',
                    sort: true,
                    templet: '#switchTpl',
                    unresize: true
                }
                , {
                    field: 'createBy',
                    title: '创建人',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'msg',
                    title: '评论语',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'picture',
                    title: '评论图',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'commentsId',
                    title: '评论任务id',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'status',
                    title: '状态',
                    width: 150,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'memberId',
                    title: '领取的用户id',
                    width: 150,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'gmt_created', title: '创建时间', templet: function (data) {
                        return dateFormat(data.create_time);
                    }, align: 'center', width: 200, sort: true
                }
                , {
                    field: 'gmt_modified', title: '修改时间', templet: function (data) {
                        return dateFormat(data.modify_time);
                    }, align: 'center', width: 200, sort: true
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center'}
            ]]
            ,
            page: true
        });

        layui.use('upload', function () {
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                , url: '/sys/comments/upload?id=${id}' //上传接口
                , exts: 'xlsx|xls'
                , done: function (req) {
                    if (req.success) {
                        search();
                        layer.msg(req.message, {icon: 1})
                    } else {
                        layer.msg(req.message, {icon: 2})
                    }
                    //上传完毕回调
                }
                , error: function () {
                    //请求异常回调
                }
            });
        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 1);
            } else {
                commonenable(this.value, 0);
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/comments/delDetail",
                    type: 'post',
                    data: {"table": table, "ids": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'translation') {
                layer_show("修改", "/sys/comments/edit?id=" + data.id, "550", "650");
            } else if (obj.event === 'del') {
                if (data.has_deleted == 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer_show("修改", "/sys/comments/edit?id=" + data.id, "550", "650");
            } else if (obj.event === 'collection') {
                layer_show("收退款创建", "/financeRecord/edit?taskId=" + data.task_id + "&category=Comments" + "&custom_id=" + data.custom, "900", "600");
            }
        });
    });

    function search() {
        searchKey = $("#keyword").val();
        marketId = $(".select").eq(0).val();
        tableIns.reload('dataTableId', {
            where: {
                table: table,
                query: {'name': ''},
                time: {'start': startDate, 'end': endDate},
                key: {'name': searchKey}
            }
            , page: {}
        });
    }


    function gradeEdit() {
        layer_show("新增", "/sys/comments/edit", "1000", "800");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }


    function commonenable(id, status) {
        $.ajax({
            url: "/sys/comments/update",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "status"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }


</script>
<!--/请在上方写此页面业务相关的脚本-->
